#!/usr/bin/python3.8
# -*- coding: utf-8 -*-
# @Time    : 2021/5/14 上午11:25
# @Author  : xushan
# @Email   : yfxushan@shwpg.com
# @File    : mqttData.py
# @Software: PyCharm

import random

from RootPath import RootPath
import os
from common.YmlUtil import YmlUtil
from common.contactStr import mqttMessageContact, sqlContact
from common.mqttUtil import on_mqtt_connect, publishMqttData
from common.KafkaUtil import KafkaProduce
from common.RedisUtil import *
from common.mysqlUtil import exc_sql
import datetime

path = os.path.join(RootPath.getRootPath(), "Application.yml")
# MySQLconf = YmlUtil().readYml(path, "mysql_test_74")
# MQTTconf = YmlUtil().readYml(path, "mqtt_test_74")

MySQLconf = YmlUtil().readYml(path, "mysql_test_219")
MQTTconf = YmlUtil().readYml(path, "mqtt_test_219")
deviceID = "10100610"


def mqttGenerator():
    point_value = {
        "OutletPressure": round(random.uniform(4, 5), 2),
        "No1FrequencyOper": 0
    }
    point_value1 = {
        "MP01": round(random.uniform(1, 5), 2)
    }
    sqldata = sqlContact(deviceID, point_value, 'hour_')
    mqttdata = json.dumps(mqttMessageContact(deviceID, point_value1))
    print(sqldata)
    print(mqttdata)
    on_mqtt_connect(MQTTconf)
    publishMqttData(MQTTconf, mqttdata)
    exc_sql(sqldata, MySQLconf)


if __name__ == '__main__':
    mqttGenerator()
